package com.http;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;

/**
 * 
 * @ClassName:JobReserveTask职位收藏
 * @Description:TODO
 * @author zhuw
 * @date 2013-8-23 下午5:58:37
 */
public class JobReserveAddTask extends AsyncTask<String, Void, ResultString> {
	public static interface CallBack extends NetWorkCallBack {
		/**
		 * 
		 * @Description:TODO
		 * @param@param data
		 * @return void
		 * @author zhuw
		 * @date 2013-8-23 下午5:58:46
		 */
		public abstract void procJobResrveAdd(String data);

	}

	CallBack callback;

	public JobReserveAddTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultString doInBackground(String... params) {
		ResultString data = null;
		try {
			ArrayList<NameValuePair> paramPairs=new ArrayList<NameValuePair>();
			paramPairs.add(new BasicNameValuePair("uid", params[0]));
			paramPairs.add(new BasicNameValuePair("jid", params[1]));
			ResEntity re=NetConUtil.postByForm(ServerPath.JOB_RESERVE_ADD_PATH,paramPairs);
			if(re.code==ResEntity.S_OK){
				  data= new ResultString(CommonData.H_FLAG_SUCCESS,null, "成功");

			}else if(re.code==ResEntity.S_FAILED){
				
				  data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+"    "+re.jsonStr, null);
				
			}else{
				  data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data= new ResultString(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultString result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procJobResrveAdd(result.result);

		} else {
			callback.procError(result.msg);
		}

	}
}
